<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改专利软著')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-zhuanliruanzhu-edit" th:object="${sciZhuanliruanzhu}">
        <input name="urlFlag" id="urlFlag" th:field="*{urlFlag}"  type="hidden">
        <input name="state" id="state" th:field="*{state}" type="hidden">
        <input name="id" id="ktid" th:field="*{id}" type="hidden">

<!--        <input name="id" th:field="*{id}" type="hidden">-->
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">学院：</label>
                <div class="col-sm-8">
                    <select name="xueyuan" class="form-control" th:with="type=${@dict.getType('sys_dept')}" required disabled="true">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{xueyuan}"></option>
                    </select>
                </div>
            </div>
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <select name="userId" class="form-control" disabled="true">
                        <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ user.userId == sciZhuanliruanzhu.userId}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">专利名称：</label>
                <div class="col-sm-8">
                    <input name="mingcheng" th:field="*{mingcheng}" class="form-control" type="text" required disabled="true">
                </div>
            </div>
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">类型：</label>
                <div class="col-sm-8">
                    <select name="leixing" class="form-control" th:with="type=${@dict.getType('sys_zhuanli_leibie')}" required disabled="true">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{leixing}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">授权号：</label>
                <div class="col-sm-8">
                    <input name="shoquanhao" th:field="*{shoquanhao}" class="form-control" type="text" required disabled="true">
                </div>
            </div>
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">获批时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="huopishijain" th:value="${#dates.format(sciZhuanliruanzhu.huopishijain, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required disabled="true">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label">是否应用：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('sys_yes_no')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="shifouyingyon" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${sciZhuanliruanzhu.shifouyingyon.contains(dict.dictValue)?true:false}" disabled="true">
                    </label>
                </div>
            </div>
            <div class="col-sm-6">
                <label class="col-sm-4 control-label">是否行业联合：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('sys_yes_no')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="hangyelianhe" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${sciZhuanliruanzhu.hangyelianhe.contains(dict.dictValue)?true:false}" disabled="true">
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">分类：</label>
                <div class="col-sm-8">
                    <select name="fenlei" class="form-control" th:with="type=${@dict.getType('sys_zhuanli_fenlei')}" required disabled="true">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{fenlei}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">排名：</label>
                <div class="col-sm-8">
                    <select name="paiming" class="form-control" th:with="type=${@dict.getType('sys_zhuanliruanzhu_fzr')}" required disabled="true">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group row">
            <div class="col-sm-6">
                <label class="col-sm-4 control-label is-required">专利文件：</label>
                <div class="col-sm-8">
                    <input th:field="*{wenjian}" hidden id="wenjian" type="text">
                    <div style="display: inline-block;">
                        <div id="wenjianFileName" style="display: inline; margin-right: 5px;"></div>
                    </div>
                    <div>
                        <button onclick="chakan()" class="btn btn-sm btn-primary color">预览</button>
                        <button onclick="downloadFile('wenjian')" class="btn btn-sm btn-primary color">下载</button>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <!-- 可以在这里添加另一个输入框，如果没有则留空 -->
            </div>
        </div>






        <h4 class="form-header h4 tdiv1" style="display:none;">退回原因</h4>
        <div class="row tdiv1" style="display:none;">
            <div class="col-sm-12">
                <div class="form-group"  >
                    <label class="col-xs-2 control-label">批注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" required maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>

            </div>
        </div>
        <h4 class="form-header h4 tdiv2"  style="display:none;">批阅记录</h4>
        <div class="row tdiv2" style="display:none;">
            <div class="col-sm-12">

                <div class="form-group"  >
                    <table id='bootstrap-table'></table>
                </div>
            </div>
        </div>

</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" id="btn1"  class="btn btn-sm btn-primary" style="display:none;" onclick="submitHandler()"><i class="fa fa-check"></i>通 过</button>&nbsp;
        <button type="button" id="btn2"  class="btn btn-sm btn-danger" style="display:none;" onclick="submitHandlerBH()"><i class="fa fa-reply-all"></i>驳 回</button>
        <button type="button" id="btn3"  class="btn btn-sm btn-warning" style="display:none;" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: select2-js" />
<script th:inline="javascript"  type="text/javascript">
    var prefix = ctx + "system/zhuanliruanzhu";
    $("#form-zhuanliruanzhu-edit").validate({
        focusCleanup: true
    });

    // function submitHandler() {
    //     if ($.validate.form()) {
    //         $.operate.save(prefix + "/edit", $('#form-zhuanliruanzhu-edit').serialize());
    //     }
    // }

    $("input[name='huopishijain']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function displayFileName(inputId, fileNameId) {
        const input = document.getElementById(inputId);
        const fileNameSpan = document.getElementById(fileNameId);
        if (input.value) {
            const fileName = input.value.split('/').pop(); // 获取文件名
            const parts = fileName.split('_'); // 按下划线分割
            const firstPart = parts[0]; // 下划线前的部分

            const dotParts = fileName.split('.'); // 按点分割
            const lastPart = dotParts[dotParts.length - 1]; // 点后的部分

            fileNameSpan.textContent = `${firstPart}.${lastPart}`; // 组合并显示
        } else {
            fileNameSpan.textContent = '';
        }
    }

    function chakan(){
        event.preventDefault();          // 阻止默认行为
        var c = $("#wenjian").val();
        $.modal.openTab("查看合同" ,c );
    }

    function downloadFile(type){
        var c = $("#"+type).val();
        if(c){
            var a = document.createElement("a");
            a.href=c;
            a.download="";
            a.style.display = "none";
            document.body.appendChild(a);
            a.click();
            document.Element.removeChild(a);
        }else{
            alert("网址无效");
        }

    }



    $(document).ready(function(){
        var kid = $("#ktid").val();
        var options = {
            url: prefix + "/bhyy/"+kid,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination:false,
            columns: [

                {
                    field : 'createTime',
                    title : '批阅时间',
                    width: 200

                } ,
                {
                    field : 'uname',
                    title : '批阅人',
                    width: 100
                },
                {
                    field : 'concate',
                    title : '内容',
                    width: 500
                },
                {
                    field : 'state',
                    title : '审核状态',
                    width: 100
                } ]
        };

        $.table.init(options);




        // $(document).ready(function(){
        //     console.log('Event Name:', name.rows);
        $('#bootstrap-table').on('load-success.bs.table', function (e, name, args) {
            console.log('Event Name:', name.rows);

            var a =$("#state").val();
            console.log('Value of a:', a);
            if ($("#urlFlag").val() == 'chakan'){
                $("#btn3").show();
                $(".tdiv2").show()
            }else {
                if(a == 2 ||a == 1 || a == 4){
                    if(name.rows.length > 0){
                        $(".tdiv2").show();
                    }
                    $(".tdiv1").show();
                    $("#btn1").show();
                    $("#btn2").show();
                    $("#btn3").show();
                }else if(a == 0){
                    $("#btn1").show();
                    $("#btn3").show();

                }

            }
        });
        });
</script>
<script th:inline="javascript">
    var prefix = ctx + "system/zhuanliruanzhu";
    $("#form-zhuanliruanzhu-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        //获取 URLflag
        var a = $("#urlFlag").val();
        console.log('Value of a:', a);

        // if ($.validate.form()) {
        $.operate.saveTab(prefix + "/hxPass", {"id":$("#ktid").val(),"urlFlag":a,"amount":$("#amount").val()});
        // $.operate.saveTab(prefix + "/hxPass", {"id":$("#ktid").val(),"urlFlag":a});
        // }
    }
    function submitHandlerBH() {
        var a = $("#urlFlag").val();
        if ($.validate.form()) {
            $.operate.saveTab(prefix + "/hxBh",   $('#form-zhuanliruanzhu-edit').serialize());
        }
    }




    // $(".file-upload").each(function (i) {
    //     var val = $("input[name='" + this.id + "']").val()
    //     $(this).fileinput({
    //         'uploadUrl': ctx + 'common/upload',
    //         initialPreviewAsData: true,
    //         initialPreview: [val],
    //         maxFileCount: 1,
    //         autoReplace: true
    //     }).on('fileuploaded', function (event, data, previewId, index) {
    //         $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    //     }).on('fileremoved', function (event, id, index) {
    //         $("input[name='" + event.currentTarget.id + "']").val('')
    //     })
    //     $(this).fileinput('_initFileActions');
    // });


    // 页面加载时显示文件名
    window.onload = function() {
        // displayFileName('contract', 'contractFileName');
        displayFileName('wenjian', 'wenjianFileName');
    };
</script>
</body>
</html>